package com.jowell.mall.order.controller;

import java.util.Arrays;
import java.util.Map;
import com.jowell.mall.order.feign.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.*;
import com.jowell.mall.order.entity.OrderEntity;
import com.jowell.mall.order.service.OrderService;
import com.jowell.common.utils.PageUtils;
import com.jowell.common.utils.Result;

/**
 * 订单
 *
 * @author Mr.ZJW
 * @email zjw@gmail.com
 * @date 2022-06-10 14:37:36
 */
@RefreshScope //动态刷新配置
@RestController
@RequestMapping("order/order")
public class OrderController {

    @Autowired
    private OrderService orderService;
    //商品中心相关接口
    @Autowired
    private ProductService productService;


    @Value("${user.name}")
    private String name;

    @GetMapping("/queryUser")
    public Result queryUser(){
        return Result.ok().put("name",name);
    }

    /**
     * @Author: Mr.ZJW
     * @Description: 查询全部商品信息
     * @Date: 2022/6/13 14:01
     **/
    @GetMapping("/products")
    private Result products() {
        return Result.ok().put("brands", productService.queryAllBrand());
    }

    /**
     * 列表
     */
    @RequestMapping("/list")
    //@RequiresPermissions("order:order:list")
    public Result list(@RequestParam Map<String, Object> params) {
        PageUtils page = orderService.queryPage(params);

        return Result.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    //@RequiresPermissions("order:order:info")
    public Result info(@PathVariable("id") Long id) {
        OrderEntity order = orderService.getById(id);

        return Result.ok().put("order", order);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    //@RequiresPermissions("order:order:save")
    public Result save(@RequestBody OrderEntity order) {
        orderService.save(order);

        return Result.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    //@RequiresPermissions("order:order:update")
    public Result update(@RequestBody OrderEntity order) {
        orderService.updateById(order);

        return Result.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    //@RequiresPermissions("order:order:delete")
    public Result delete(@RequestBody Long[] ids) {
        orderService.removeByIds(Arrays.asList(ids));

        return Result.ok();
    }

}
